#pragma once
/************************************************************************/
/* Helper: this class is used to do something trivial                                                                    */
/************************************************************************/
#include <iostream>
#include <sstream>
#include <iomanip>
namespace Utility{
class Helper
{
public:
	Helper(void);
	~Helper(void);
	
public:
	static void				errInfoDialog(const TCHAR* msg, const TCHAR* title = L"Error");

	//convert data(int, float, double) to CString
	//assume that Unicode is defined
	template<typename T>
	static CString			convertToCString(const T& val);

	//convert any type to std::string
	template<typename T>
	static std::string		convertToString(const T& val);

	//assume that Unicode is defined
	static std::string		convertCStringToString(CString& cstr);

	//return in format: 2012/7/16 12:26:31
	static std::string		getCurrentTime();	

	//convert to std::string in hex
	template<typename T>
	static std::string		getHexValueString(const T& val);
};

template<typename T>
std::string Helper::convertToString(const T& val)
{
	std::string str;
	std::stringstream strStream;
	strStream<<val;
	strStream>>str;
	return str;
}

template<typename T>
CString Helper::convertToCString( const T& val )
{
	float tempVal = (float)val;
	CString cstr;
	cstr.Format(L"%.3f", val);
	return cstr;
}

template<typename T>
std::string Helper::getHexValueString(const T& val)
{
	std::stringstream sstream;
	sstream<< "0x"<< std::setfill('0')<< std::setw(8) << std::hex << val;
	std::string str;
	sstream>> str;
	return str;
}

/************************************************************************/
/*TimeCounter: this class is used to count  the time elapsed
/*reference:
/*http://www.cnblogs.com/chuncn/archive/2009/03/25/1421050.html 
/************************************************************************/
class  TimeCounter
{
public:
	TimeCounter(void);
	~TimeCounter(void);
	void				Start() ;         
	void				End();             
	void				Reset();
	float				getElapseTime();
private:
	LONGLONG			_freq;
	LARGE_INTEGER		_begin;
	LARGE_INTEGER		_end;
	float				costTime;  //in second
};
};

